



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class CoursesScoesDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public CoursesScoesDB()
        {
        }

        public CoursesScoesDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<CoursesScoes> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<CoursesScoes> lstRet = new List<CoursesScoes>();

            string strQuery = " select " + strTop  + " * from dbo.[CoursesScoes]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    CoursesScoes obj = new CoursesScoes();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["ScoName"] != DBNull.Value)
                    {
                        obj.ScoName = (System.String)dr["ScoName"];
                    }
                    else
                    {
                        obj.ScoName = "";
                    } 
 if (dr["ScoData"] != DBNull.Value)
                    {
                        obj.ScoData = (System.String)dr["ScoData"];
                    }
                    else
                    {
                        obj.ScoData = "";
                    } 
 if (dr["IsCompleted"] != DBNull.Value)
                    {
                        obj.IsCompleted = (System.Boolean)dr["IsCompleted"];
                    }
                    else
                    {
                        obj.IsCompleted = false;
                    } 
 if (dr["RegisteredCoursesID"] != DBNull.Value)
                    {
                        obj.RegisteredCoursesID = (System.Int64)dr["RegisteredCoursesID"];
                    }
                    else
                    {
                        obj.RegisteredCoursesID = -1;
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<CoursesScoes> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<CoursesScoes> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , CoursesScoes obj)
        {
            
            

                    DbParameter prmScoName = con.createParameter();
                    prmScoName.ParameterName = "@ScoName";
                    prmScoName.DbType =DbType.String;
                    if (obj.ScoName == null)
                    {
                        prmScoName.Value = DBNull.Value;
                    }
                    else
                    {
                        prmScoName.Value = obj.ScoName;
                    }
                

                    


                    DbParameter prmScoData = con.createParameter();
                    prmScoData.ParameterName = "@ScoData";
                    prmScoData.DbType =DbType.String;
                    if (obj.ScoData == null)
                    {
                        prmScoData.Value = DBNull.Value;
                    }
                    else
                    {
                        prmScoData.Value = obj.ScoData;
                    }
                

                    


                    DbParameter prmIsCompleted = con.createParameter();
                    prmIsCompleted.ParameterName = "@IsCompleted";
                    prmIsCompleted.DbType =DbType.Boolean;
                    if (obj.IsCompleted == null)
                    {
                        prmIsCompleted.Value = DBNull.Value;
                    }
                    else
                    {
                        prmIsCompleted.Value = obj.IsCompleted;
                    }
                

                    


                    DbParameter prmRegisteredCoursesID = con.createParameter();
                    prmRegisteredCoursesID.ParameterName = "@RegisteredCoursesID";
                    prmRegisteredCoursesID.DbType =DbType.Int64;
                    if (obj.RegisteredCoursesID == null)
                    {
                        prmRegisteredCoursesID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmRegisteredCoursesID.Value = obj.RegisteredCoursesID;
                    }
                

                    


           



            string strQuery = " insert into dbo.[CoursesScoes] ([ScoName],[ScoData],[IsCompleted],[RegisteredCoursesID]) VALUES (@ScoName,@ScoData,@IsCompleted,@RegisteredCoursesID) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmScoName,prmScoData,prmIsCompleted,prmRegisteredCoursesID);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(CoursesScoes obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, CoursesScoes obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmScoName = con.createParameter();
                    prmScoName.ParameterName = "@ScoName";
                    prmScoName.DbType =DbType.String;
                    if (obj.ScoName == null)
                    {
                        prmScoName.Value = DBNull.Value;
                    }
                    else
                    {
                        prmScoName.Value = obj.ScoName;
                    }
                

                    


                    DbParameter prmScoData = con.createParameter();
                    prmScoData.ParameterName = "@ScoData";
                    prmScoData.DbType =DbType.String;
                    if (obj.ScoData == null)
                    {
                        prmScoData.Value = DBNull.Value;
                    }
                    else
                    {
                        prmScoData.Value = obj.ScoData;
                    }
                

                    


                    DbParameter prmIsCompleted = con.createParameter();
                    prmIsCompleted.ParameterName = "@IsCompleted";
                    prmIsCompleted.DbType =DbType.Boolean;
                    if (obj.IsCompleted == null)
                    {
                        prmIsCompleted.Value = DBNull.Value;
                    }
                    else
                    {
                        prmIsCompleted.Value = obj.IsCompleted;
                    }
                

                    


                    DbParameter prmRegisteredCoursesID = con.createParameter();
                    prmRegisteredCoursesID.ParameterName = "@RegisteredCoursesID";
                    prmRegisteredCoursesID.DbType =DbType.Int64;
                    if (obj.RegisteredCoursesID == null)
                    {
                        prmRegisteredCoursesID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmRegisteredCoursesID.Value = obj.RegisteredCoursesID;
                    }
                

                    


           



            string strQuery = " update dbo.[CoursesScoes] set [ScoName]=@ScoName,[ScoData]=@ScoData,[IsCompleted]=@IsCompleted,[RegisteredCoursesID]=@RegisteredCoursesID where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmScoName,prmScoData,prmIsCompleted,prmRegisteredCoursesID);

            

        }


        public void Update(CoursesScoes obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, CoursesScoes obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[CoursesScoes]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( CoursesScoes obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<CoursesScoes> getCoursesScoesByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<CoursesScoes> lstRet = new List<CoursesScoes>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<CoursesScoes> getCoursesScoesByID(System.Int64 ID)
                    {
                        List<CoursesScoes> lstRet = new List<CoursesScoes>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getCoursesScoesByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<CoursesScoes> getCoursesScoesByScoName(ClassDataHandler con,System.String ScoName)
                    {
                        List<CoursesScoes> lstRet = new List<CoursesScoes>();


                        DbParameter prmScoName = con.createParameter();
                        prmScoName.ParameterName = "@ScoName";
                        prmScoName.DbType = DbType.String;
                        if (ScoName == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmScoName.Value = ScoName;
                        }


                        lstRet = Select(con, "" , " where [ScoName]=@ScoName ", prmScoName);



                        return lstRet;

                    }


                    public List<CoursesScoes> getCoursesScoesByScoName(System.String ScoName)
                    {
                        List<CoursesScoes> lstRet = new List<CoursesScoes>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getCoursesScoesByScoName(con, ScoName);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<CoursesScoes> getCoursesScoesByScoData(ClassDataHandler con,System.String ScoData)
                    {
                        List<CoursesScoes> lstRet = new List<CoursesScoes>();


                        DbParameter prmScoData = con.createParameter();
                        prmScoData.ParameterName = "@ScoData";
                        prmScoData.DbType = DbType.String;
                        if (ScoData == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmScoData.Value = ScoData;
                        }


                        lstRet = Select(con, "" , " where [ScoData]=@ScoData ", prmScoData);



                        return lstRet;

                    }


                    public List<CoursesScoes> getCoursesScoesByScoData(System.String ScoData)
                    {
                        List<CoursesScoes> lstRet = new List<CoursesScoes>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getCoursesScoesByScoData(con, ScoData);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<CoursesScoes> getCoursesScoesByIsCompleted(ClassDataHandler con,System.Boolean IsCompleted)
                    {
                        List<CoursesScoes> lstRet = new List<CoursesScoes>();


                        DbParameter prmIsCompleted = con.createParameter();
                        prmIsCompleted.ParameterName = "@IsCompleted";
                        prmIsCompleted.DbType = DbType.Boolean;
                        if (IsCompleted == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmIsCompleted.Value = IsCompleted;
                        }


                        lstRet = Select(con, "" , " where [IsCompleted]=@IsCompleted ", prmIsCompleted);



                        return lstRet;

                    }


                    public List<CoursesScoes> getCoursesScoesByIsCompleted(System.Boolean IsCompleted)
                    {
                        List<CoursesScoes> lstRet = new List<CoursesScoes>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getCoursesScoesByIsCompleted(con, IsCompleted);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<CoursesScoes> getCoursesScoesByRegisteredCoursesID(ClassDataHandler con,System.Int64 RegisteredCoursesID)
                    {
                        List<CoursesScoes> lstRet = new List<CoursesScoes>();


                        DbParameter prmRegisteredCoursesID = con.createParameter();
                        prmRegisteredCoursesID.ParameterName = "@RegisteredCoursesID";
                        prmRegisteredCoursesID.DbType = DbType.Int64;
                        if (RegisteredCoursesID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmRegisteredCoursesID.Value = RegisteredCoursesID;
                        }


                        lstRet = Select(con, "" , " where [RegisteredCoursesID]=@RegisteredCoursesID ", prmRegisteredCoursesID);



                        return lstRet;

                    }


                    public List<CoursesScoes> getCoursesScoesByRegisteredCoursesID(System.Int64 RegisteredCoursesID)
                    {
                        List<CoursesScoes> lstRet = new List<CoursesScoes>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getCoursesScoesByRegisteredCoursesID(con, RegisteredCoursesID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<CoursesScoes> Search(ClassDataHandler con, CoursesScoes obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.ScoName != "")
                    {
                        DbParameter prmScoName = con.createParameter();
                        prmScoName.ParameterName = "@ScoName";
                        prmScoName.DbType =DbType.String;
                        if (obj.ScoName == null)
                        {
                            prmScoName.Value = DBNull.Value;
                        }
                        else
                        {
                            prmScoName.Value = obj.ScoName;
                        }
                        strWhere += " [ScoName]=@ScoName AND ";
                        lstParameters.Add(prmScoName);
                     }



                    

                    if (obj.ScoData != "")
                    {
                        DbParameter prmScoData = con.createParameter();
                        prmScoData.ParameterName = "@ScoData";
                        prmScoData.DbType =DbType.String;
                        if (obj.ScoData == null)
                        {
                            prmScoData.Value = DBNull.Value;
                        }
                        else
                        {
                            prmScoData.Value = obj.ScoData;
                        }
                        strWhere += " [ScoData]=@ScoData AND ";
                        lstParameters.Add(prmScoData);
                     }



                    

                    if (obj.IsCompleted != false)
                    {
                        DbParameter prmIsCompleted = con.createParameter();
                        prmIsCompleted.ParameterName = "@IsCompleted";
                        prmIsCompleted.DbType =DbType.Boolean;
                        if (obj.IsCompleted == null)
                        {
                            prmIsCompleted.Value = DBNull.Value;
                        }
                        else
                        {
                            prmIsCompleted.Value = obj.IsCompleted;
                        }
                        strWhere += " [IsCompleted]=@IsCompleted AND ";
                        lstParameters.Add(prmIsCompleted);
                     }



                    

                    if (obj.RegisteredCoursesID != -1)
                    {
                        DbParameter prmRegisteredCoursesID = con.createParameter();
                        prmRegisteredCoursesID.ParameterName = "@RegisteredCoursesID";
                        prmRegisteredCoursesID.DbType =DbType.Int64;
                        if (obj.RegisteredCoursesID == null)
                        {
                            prmRegisteredCoursesID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmRegisteredCoursesID.Value = obj.RegisteredCoursesID;
                        }
                        strWhere += " [RegisteredCoursesID]=@RegisteredCoursesID AND ";
                        lstParameters.Add(prmRegisteredCoursesID);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<CoursesScoes> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<CoursesScoes> Search(CoursesScoes obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<CoursesScoes> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<CoursesScoes> SearchOrLike(ClassDataHandler con, CoursesScoes obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.ScoName != "")
                    {
                        DbParameter prmScoName = con.createParameter();
                        prmScoName.ParameterName = "@ScoName";
                        prmScoName.DbType =DbType.String;
                        if (obj.ScoName == null)
                        {
                            prmScoName.Value = DBNull.Value;
                        }
                        else
                        {
                            prmScoName.Value = obj.ScoName;
                        }
                        strWhere += " [ScoName] LIKE @ScoName OR ";
                        lstParameters.Add(prmScoName);
                     }



                    

                    if (obj.ScoData != "")
                    {
                        DbParameter prmScoData = con.createParameter();
                        prmScoData.ParameterName = "@ScoData";
                        prmScoData.DbType =DbType.String;
                        if (obj.ScoData == null)
                        {
                            prmScoData.Value = DBNull.Value;
                        }
                        else
                        {
                            prmScoData.Value = obj.ScoData;
                        }
                        strWhere += " [ScoData] LIKE @ScoData OR ";
                        lstParameters.Add(prmScoData);
                     }



                    

                    if (obj.IsCompleted != false)
                    {
                        DbParameter prmIsCompleted = con.createParameter();
                        prmIsCompleted.ParameterName = "@IsCompleted";
                        prmIsCompleted.DbType =DbType.Boolean;
                        if (obj.IsCompleted == null)
                        {
                            prmIsCompleted.Value = DBNull.Value;
                        }
                        else
                        {
                            prmIsCompleted.Value = obj.IsCompleted;
                        }
                        strWhere += " [IsCompleted]=@IsCompleted OR ";
                        lstParameters.Add(prmIsCompleted);
                     }



                    

                    if (obj.RegisteredCoursesID != -1)
                    {
                        DbParameter prmRegisteredCoursesID = con.createParameter();
                        prmRegisteredCoursesID.ParameterName = "@RegisteredCoursesID";
                        prmRegisteredCoursesID.DbType =DbType.Int64;
                        if (obj.RegisteredCoursesID == null)
                        {
                            prmRegisteredCoursesID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmRegisteredCoursesID.Value = obj.RegisteredCoursesID;
                        }
                        strWhere += " [RegisteredCoursesID]=@RegisteredCoursesID OR ";
                        lstParameters.Add(prmRegisteredCoursesID);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<CoursesScoes> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<CoursesScoes> SearchOrLike(CoursesScoes obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<CoursesScoes> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            